package com.ssyc.gsk_tk.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.gsk_tk.R;
import com.ssyc.gsk_tk.bean.PanelInfo;

import java.util.List;

/**
 * 展示题目的面板的GridView的适配器
 * Created by Administrator on 2018/9/19 0019.
 */

public class PanelGvAdapter extends CommonAdapter<PanelInfo> {
    private Context context;
    private onTvClickListener listener;

    public PanelGvAdapter(Context context, List<PanelInfo> datas, int layoutId) {
        super(context, datas, layoutId);
        this.context = context;
    }

    @Override
    public void convert(ViewHolder holder, PanelInfo panelInfo) {
        int position = holder.getPosition();
        TextView tv = holder.getView(R.id.tv);
        tv.setText((position + 1) + "");
        //根据完成的状态来设置背景和文字颜色
        //状态值,0表示未完成,1表示已完成
        if (panelInfo.state == 1) {
            //已完成
            tv.setBackgroundResource(R.drawable.tk_tv_competed);
        } else {
            tv.setBackgroundResource(R.drawable.tk_tv_no_competed);
        }

        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onClick(position);
                }
            }
        });
    }


    public void setOnTvClickListener(onTvClickListener listener) {
        this.listener = listener;
    }

    /**
     * 回调事件
     */
    public interface onTvClickListener {
        void onClick(int pos);
    }
}
